:art: rtemperature

huangqimin001 3 years ago
parent
commit
3c0227dab1
3 changed files with 21 additions and 5 deletions
  1. 5 2
      api/eqpt_views.py
  2. 4 3
      utils/redis/rkeys.py
  3. 12 0
      utils/redis/rtemperature.py

+ 5 - 2
api/eqpt_views.py

@@ -18,6 +18,7 @@ from equipment.models import (IsolationPointInfo, IsolationPointUserInfo, Thermo
18 18
 from utils.age import stamp2age
19 19
 from utils.error.errno_utils import IsolationPointStatusCode, ThermometerEquipmentStatusCode
20 20
 from utils.redis.rscreen import get_screen_info, set_screen_info
21
+from utils.redis.rtemperature import get_old_temperature, set_old_temperature
21 22
 
22 23
 
23 24
 @logit
@@ -213,13 +214,13 @@ def get_screen_data(point=None, point_id=None):
213 214
     macids = eqpts.values_list('macid', flat=True)
214 215
 
215 216
     logs = ThermometerMeasureInfo.objects.filter(
216
-        point_id=point_id,
217
+        point_id=point.point_id,
217 218
         point_measure_ymd=tc.local_string(format='%Y-%m-%d'),
218 219
         point_measure_window=point.previous_measure_window,
219 220
         macid__in=macids,
220 221
         status=True,
221 222
     ).values('macid', 'temperature')
222
-    logs = {log.get('macid'): log.get('temperature') for log in logs}
223
+    logs = {log.get('macid'): log.get('temperature') or get_old_temperature(point.point_id, log.get('macid')) for log in logs}
223 224
 
224 225
     infos = IsolationPointUserInfo.objects.filter(point_id=point.point_id, status=True).values('pk', 'fields')
225 226
     infos = {info.get('pk'): info.get('fields') for info in infos}
@@ -403,4 +404,6 @@ def mqtt_upload_temperature(payload):
403 404
             measure_info.temperature = temperature
404 405
             measure_info.save()
405 406
 
407
+            set_old_temperature(eqpt.point_id, macid, temperature)
408
+
406 409
     set_screen_info(point.point_id, get_screen_data(point))

+ 4 - 3
utils/redis/rkeys.py

@@ -1,5 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-TWJC_QRCODE_URL_HASH = 'twjc:qrcode:url:hash'  # scene:qrcode_url
4
-TWJC_POINT_INFO = 'twjc:point:info:%s'  # uuid:point_id
5
-TWJC_SCREEN_INFO = 'twjc:screen:info:%s'  # point_id:screen_info
3
+TWJC_QRCODE_URL_HASH = 'twjc:qrcode:url:hash'  # HASH, scene:qrcode_url
4
+TWJC_OLD_TEMPERATURE_HASH = 'twjc:old:temperature:hash'  # HASH, point_id+macid:temperature
5
+TWJC_POINT_INFO = 'twjc:point:info:%s'  # uuid, point_id
6
+TWJC_SCREEN_INFO = 'twjc:screen:info:%s'  # point_id, screen_info

+ 12 - 0
utils/redis/rtemperature.py

@@ -0,0 +1,12 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from utils.redis.connect import r
4
+from utils.redis.rkeys import TWJC_OLD_TEMPERATURE_HASH
5
+
6
+
7
+def set_old_temperature(point_id, macid, temperature):
8
+    r.hset(TWJC_OLD_TEMPERATURE_HASH, f'{point_id}:{macid}', temperature)
9
+
10
+
11
+def get_old_temperature(point_id, macid):
12
+    return r.hgetfloat(TWJC_OLD_TEMPERATURE_HASH, f'{point_id}:{macid}')